Fix Lengow order import failure on PS 1.7.8.8 with catalog/maintenance mode#85
Fix Lengow order import failure on PS 1.7.8.8 with catalog/maintenance mode#85
Conversation
- Replace Attribute::getAttributeMinimalQty() / ProductAttribute::getAttributeMinimalQty() version-check block with new Combination()->minimal_quantity which works on all PS versions - Replace Context::getContext() with LengowContext::getContext() in updateQty() (2 places) to ensure the correct shop context is used during cron import - Add containsProduct() method to LengowCart for explicit control - Add _updateCustomizationQuantity() method to LengowCart for explicit control Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/c3d757de-91f0-4eb2-bd1d-ee0889feed55 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
|
J'ai cette erreur: 026-04-15 11:42:06 - [E_ERROR] Uncaught Error: Class 'LengowContext' not found in /home/crosstalk/www/oferta/modules/lengow/classes/models/LengowCart.php:121 |
…es not exist on 3.x branch Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/bc2c8168-d6f3-4b59-96b3-8ec2c07bdb42 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
Fixed in commit |
|
[E_PARSE] syntax error, unexpected '|', expecting ';' or '{' |
…s causing parse error on PHP 7.x Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/2bd12b7d-2251-4035-af96-232578877075 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
Fixed in commit |
On PrestaShop 1.7.8.8, Lengow order import fails with
product could not be added to cartwhenPS_CATALOG_MODEis active, becauseLengowCart::updateQty()had a bug that broke the import flow even whenforceProduct = true.Changes in
classes/models/LengowCart.phpAttribute::getAttributeMinimalQty()does not exist on PS 1.7 — the version-check block fell into theelsebranch on PS 1.7.x and called a non-existent method. Replaced withnew Combination((int) $idProductAttribute)->minimal_quantity, which is correct on all PS versions (1.6 / 1.7 / 8 / 9):Shop context —
Context::getContext()is used in both places withinupdateQty(). TheLengowContextclass does not exist on the3.xbranch, so the native PrestaShopContext::getContext()is retained.Original prompt
Context
On PrestaShop 1.7.8.8, Lengow order import fails when the shop is in maintenance mode (PS_CATALOG_MODE enabled). The error in logs is:
The
forceProductoption is enabled in Lengow configuration and should bypass all stock/availability checks, but it does not work.Root cause analysis
The file
classes/models/LengowCart.phpon branch3.xhas the following issues:Bug 1:
Attribute::getAttributeMinimalQty()does not exist on PS 1.7.8.8Lines 139-146 have a version check:
On PS 1.7.8.8,
version_compare('1.7.8.8', '8.0.0.0', '>=')isfalse, so it callsAttribute::getAttributeMinimalQty(). But this method does not exist on theAttributeclass in PS 1.7.8. TheAttributeclass in PS 1.7 represents product attributes (color, size), NOT combinations. This causes a fatal error or returns an unexpected value.Fix: Replace with
new Combination((int) $idProductAttribute)->minimal_quantitywhich works on ALL PrestaShop versions (1.6, 1.7, 8, 9). TheCombinationclass has always had theminimal_quantityproperty mapped to theproduct_attributetable.Bug 2:
Context::getContext()instead ofLengowContext::getContext()Line 121:
$shop = Context::getContext()->shop;Line 244:
$context = Context::getContext()->cloneContext();The
LengowImport::changeContext()method configures the correct shop on the context accessible viaLengowContext::getContext(), but the globalContext::getContext()may not have the correct shop during cron import. This causesProduct::sqlStock()to query stock for the wrong shop and theINSERT INTO cart_productto use a wrongid_shop.Fix: Replace
Context::getContext()withLengowContext::getContext()in both places. Note:LengowContextclass exists on the3.xbranch — check it first to confirm. IfLengowContextdoes NOT exist on the3.xbranch, keepContext::getContext()as-is.Bug 3: Missing
containsProduct()and_updateCustomizationQuantity()methodsThe
updateQty()method calls$this->containsProduct()and$this->_updateCustomizationQuantity(). On PS 1.7.8.8, the parentCartclass providescontainsProduct()natively, so this is fine. However_updateCustomizationQuantity()is a protected method onCartthat may have a different signature. SinceLengowCart extends Cart, the parent methods are inherited and should work.However, to be safe and ensure correct behavior, add both methods explicitly to
LengowCart:Add
containsProduct()method:Add
_updateCustomizationQuantity()method: